home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / Dev / TileForth / doc / forth.txt next >
Text File  |  1995-08-25  |  46KB  |  1,058 lines

  1.  
  2.  
  3.  
  4.           FORTH(3X)                                               FORTH(3X)
  5.  
  6.  
  7.           NAME
  8.                  forth   forth-83  standard  word set and tile forth kernel
  9.                  extensions
  10.  
  11.           SYNOPSIS
  12.                  forth
  13.  
  14.           DESCRIPTION
  15.                  The required word set of Forth-83 Standard  excluding  the
  16.                  block  file word set and the tile forth kernel extensions.
  17.                  Each  "word"  (function,  procedure,  variable,  etc)   is
  18.                  described  with  its  stack action, parameters, and return
  19.                  values and its code type. The format of the glossary  list
  20.                  is:
  21.                  <type> <name> ( <stack-effect> ) [ <mode> ]
  22.                  The  <stack-effect>  describes  the  parameter  and return
  23.                  values for the word in the following format:
  24.                  ( <arguments> -- <returns>)
  25.                  The arguments and return values are  given  from  left  to
  26.                  right  with  the deepest stack value first. Symbolic names
  27.                  are often used for the arguments while the  return  values
  28.                  are often only described by data type.
  29.  
  30.                  The optional <mode> may define how the word is interpreted
  31.                  and when it is visible. The  mode  "immediate"  marks  the
  32.                  word  as always executed. The mode "execution" reduces the
  33.                  words visibility to only execution, i.e.,  interpretation,
  34.                  mode.  The mode "compilation" reduces the words visibility
  35.                  to only compilation mode. Last, the mode  "private"  marks
  36.                  the  words  as  only visible in the vocabulary where it is
  37.                  defined. Additional modes are added by  other  tile  forth
  38.                  extensions.
  39.  
  40.                  The  list  of  required words in the Forth-83 Standard are
  41.                  described   in   the   following   sub-sections;    "Stack
  42.                  Manipulation",  "Memory  Access",  "Logic",  "Arithmetic",
  43.                  "Comparison", "Numeric Conversion", "Control  Structures",
  44.                  "Terminal  Input/Output", "Interpreter", "Vocabulary", and
  45.                  "Defining Words". Each  sub-section  is  sorted  in  ASCII
  46.                  order.
  47.  
  48.              Stack Manipulation
  49.                  The   Forth-83   Standard   parameter   and  return  stack
  50.                  manipulation  functions.  The  tile  forth   kernel   also
  51.                  supports the double number stack manipulation extension.
  52.  
  53.                  code -rot ( x y z -- z x y)
  54.                         The  top  three  stack entries are rotated, forcing
  55.                         the top to become the deepest of the three.
  56.  
  57.                  code 2>r ( x y -- ) compilation
  58.                         Double "to-r". "x" and "y" are transferred  to  the
  59.                         return stack.
  60.  
  61.  
  62.  
  63.  
  64.                                   September 17, 1990                      1
  65.  
  66.  
  67.  
  68.  
  69.  
  70.           FORTH(3X)                                               FORTH(3X)
  71.  
  72.  
  73.                  code 2drop ( x y -- )
  74.                         Double "drop". "x" and "y" are dropped.
  75.  
  76.                  code 2dup ( x1 y1 -- x1 y1 x1 y1)
  77.                         Double "dup". The first pair is copied.
  78.  
  79.                  code 2over (x1 y1 x2 y2 -- x1 y1 x2 y2 x1 y1)
  80.                         Double "over". The second pair is copied.
  81.  
  82.                  code 2r> ( -- x y) compilation
  83.                         Double  "from-r".  "x" and "y" are removed from the
  84.                         return stack and transferred to the data stack.
  85.  
  86.                  code 2rot ( x1 y1 x2 y2 x3 y3 -- x2 y2 x3 y3 x1 y1)
  87.                         Double "rot". The three pairs change places.
  88.  
  89.                  code 2swap ( x1 y1 x2 y2 -- x2 y2 x1 y1)
  90.                         Double "swap". The two pairs change places.
  91.  
  92.                  code >r ( x -- ) compilation
  93.                         Transfer "x" to the return stack.
  94.  
  95.                  code ?dup ( x -- [x x] or [x])
  96.                         Duplicate "x" if it is non-zero.
  97.  
  98.                  code depth ( -- +n)
  99.                         "+n" is the number of values contained in the  data
  100.                         stack before "+n" was placed on the stack.
  101.  
  102.                  code drop ( x -- )
  103.                         "x" is removed from the stack.
  104.  
  105.                  code dup ( x -- x x)
  106.                         Duplicate "x".
  107.  
  108.                  code nip ( x y -- y)
  109.                         The second stack element "x" is removed.
  110.  
  111.                  code over ( x y -- x y x)
  112.                         A copy of "x" is made and moved over "y".
  113.  
  114.                  code pick ( +n -- x)
  115.                         "x"  is  a  copy  of the "+n"-th stack element, not
  116.                         counting "+n" itself. [0..depth-1]
  117.                         "0 pick" is equivalent to "dup"
  118.                         "1 pick" is equivalent to "over"
  119.  
  120.                  code r> ( -- x) compilation
  121.                         "x"  is  removed  from   the   return   stack   and
  122.                         transferred to the data stack.
  123.  
  124.                  code r@ ( -- x) compilation
  125.                         "x" is a copy of the top of the return stack.
  126.  
  127.  
  128.  
  129.  
  130.                                   September 17, 1990                      2
  131.  
  132.  
  133.  
  134.  
  135.  
  136.           FORTH(3X)                                               FORTH(3X)
  137.  
  138.  
  139.                  code roll ( +n -- )
  140.                         The  "+n"-th  stack value, not counting "+n" itself
  141.                         is first removed and then transferred to the top of
  142.                         the  stack,  moving  the  remaining values into the
  143.                         vacated position. The parameter should  be  in  the
  144.                         interval: [0..depth-1].
  145.                         "0 roll" is a null operation
  146.                         "1 roll" is equivalent to "swap"
  147.                         "2 roll" is equivalent to "rot"
  148.  
  149.                  code rot ( x y z -- y z x)
  150.                         The  top  three stack entries are rotated, bringing
  151.                         the deepest to the top.
  152.  
  153.                  code swap ( x y -- y x)
  154.                         The top two stack entries are exchanged.
  155.  
  156.                  code tuck ( x y -- y x y)
  157.                         A copy of "y" is tucked under "x".
  158.  
  159.              Memory Access
  160.                  The Forth-83 Standard memory and data access word set. The
  161.                  tile  forth  kernel  extends  the  Forth-83  Standard with
  162.                  additional access functions for bit testing and bit  field
  163.                  access. All access to memory is achieved through this word
  164.                  set.
  165.  
  166.                  code ! ( 32b addr -- )
  167.                         The postfix assignment  operator.  Store  "32b"  at
  168.                         "addr".
  169.  
  170.                  code +! ( x1 addr -- )
  171.                         "x1"  is  added  to  the  value at "addr" using the
  172.                         convention for "+". The value at "addr" is  assumed
  173.                         to  be  of  size  "cell".   The  sum  replaces  the
  174.                         original value at "addr".
  175.  
  176.                  code -match ( addr1 addr2 n -- bool)
  177.                         Matches the strings at address "addr1" and  "addr2"
  178.                         of  length  "n" at the parameter addresses. Returns
  179.                         "false" if the strings are equal  else  "true".  If
  180.                         the  length  "n"  is  zero the function will return
  181.                         "true".
  182.  
  183.                  code -trailing ( addr +n1 -- addr +n2)
  184.                         The  character  counter  "+n1"  of  a  text  string
  185.                         beginning at "addr" is adjusted to exclude trailing
  186.                         spaces. If "+n1" is zero, then "+n2"  is  zero.  If
  187.                         the entire string consists of spaces, then "+n2" is
  188.                         zero.
  189.  
  190.                  code <c@ ( addr -- 8b)
  191.                         "8b" is the value at  "addr".  The  value  is  sign
  192.                         extended to the stack (cell) width.
  193.  
  194.  
  195.  
  196.                                   September 17, 1990                      3
  197.  
  198.  
  199.  
  200.  
  201.  
  202.           FORTH(3X)                                               FORTH(3X)
  203.  
  204.  
  205.                  code <f@ ( x p w -- y)
  206.                         Field  access within a 32-bit quantity. "y" are the
  207.                         bits within "x" at position  "p"  and  with  a  bit
  208.                         field  width,  "w". Bits positions are counted from
  209.                         right to  left  starting  with  zero.  A  field  is
  210.                         defined from a position and upwards. The result "y"
  211.                         is sign extended.
  212.  
  213.                  code <w@ ( addr -- 16b)
  214.                         "16b" is the value at "addr".  The  value  is  sign
  215.                         extended to the stack (cell) width.
  216.  
  217.                  code @ ( addr -- 32b)
  218.                         "32b"  is  the  value  at  "addr". Primary variable
  219.                         value access function.
  220.  
  221.                  code b! ( x y p -- z)
  222.                         Returns "z", the  result  of  setting  the  bit  at
  223.                         position  "p" in "y" according to the value of "x".
  224.                         The bit is set to zero if "x" is zero else one.
  225.  
  226.                  code b@ ( x p -- y)
  227.                         Returns "true" if the bit a position "p" in "x"  is
  228.                         one else "false".
  229.  
  230.                  code bounds ( addr1 n -- addr2 addr1)
  231.                         Converts   vector  address  and  size  to  boundary
  232.                         address suitable for a "do"-loop.  "addr2"  is  the
  233.                         end address of the vector, i.e., the sum of "addr1"
  234.                         and "n".
  235.  
  236.                  code c! ( 8b addr -- )
  237.                         The postfix  assignment  operator.  Store  "8b"  at
  238.                         "addr".
  239.  
  240.                  code c@ ( addr -- 8b)
  241.                         "8b"  is the value at "addr". The value is not sign
  242.                         extended.
  243.  
  244.                  code cmove ( addr1 addr2 u -- )
  245.                         Move the "u" bytes at address "addr1"  to  "addr2".
  246.                         The  byte  at  "addr1"  is  moved first, proceeding
  247.                         toward high memory.  If  "u"  is  zero  nothing  is
  248.                         moved.
  249.  
  250.                  code cmove> ( addr1 addr2 u -- )
  251.                         Move  the  "u" bytes at address "addr1" to "addr2".
  252.                         The   move   begins   by   moving   the   byte   at
  253.                         ("addr1"+"u"-1)  to ("addr2"+"u"-1) and proceeds to
  254.                         successively lower addresses for "u" bytes.  If "u"
  255.                         is  zero  nothing  is  moved.  Useful for sliding a
  256.                         string towards higher addresses.
  257.  
  258.  
  259.  
  260.  
  261.  
  262.                                   September 17, 1990                      4
  263.  
  264.  
  265.  
  266.  
  267.  
  268.           FORTH(3X)                                               FORTH(3X)
  269.  
  270.  
  271.                  code count ( addr1 -- addr2 +n)
  272.                         "addr2" is "addr1"+1 and "+n" is the length of  the
  273.                         counted   string   at  "addr1".  The  byte  "addr1"
  274.                         contains the byte count  "+n".  Range  of  "+n"  is
  275.                         [0..255].
  276.  
  277.                  code f! ( x y p w -- z)
  278.                         Inserts  the value of "x" into "y" at the bit field
  279.                         which is defined by the position "p" and  with  the
  280.                         width "w". The value "x" is shifted and masked into
  281.                         "y" to form the result "z".
  282.  
  283.                  code f@ ( x p w -- y)
  284.                         Field access within a 32-bit quantity. "y" are  the
  285.                         bits  within  "x"  at  position  "p" and with a bit
  286.                         field width, "w". Bits positions are  counted  from
  287.                         right  to  left  starting  with  zero.  A  field is
  288.                         defined from a position and upwards.
  289.  
  290.                  code fill ( addr u 8b -- )
  291.                         "u" bytes of memory beginning at "addr" are set  to
  292.                         "8b".  No action is taken is "u" is zero.
  293.  
  294.                  code w! ( 16b addr -- )
  295.                         The  postfix  assignment  operator.  Store "16b" at
  296.                         "addr".
  297.  
  298.                  code w@ ( addr -- 16b)
  299.                         "16b" is the value at "addr". The value is not sign
  300.                         extended.
  301.  
  302.              Logic
  303.                  The  Forth-83  Standard  logic  functions.  The tile forth
  304.                  kernel  extends  the  basic  function  set  with   boolean
  305.                  constants  and  a  boolean  conversion function. All logic
  306.                  functions manipulate their parameters bit-by-bit.
  307.  
  308.                  code and ( 32b1 32b2 -- 32b3)
  309.                         "32b3" is the bit-by-bit logical and of "32b1"  and
  310.                         "32b2".
  311.  
  312.                  code boolean ( n -- bool)
  313.                         Maps  numerical value to a boolean value, "true" or
  314.                         "false".  Non-zero values are mapped to "true"  and
  315.                         zero to "false".
  316.  
  317.                  constant false ( -- 0)
  318.                         The constant "false" represented by the value zero.
  319.  
  320.                  code or ( 32b1 32b2 -- 32b3)
  321.                         "32b3" is the  bit-by-bit  inclusive-or  of  "32b1"
  322.                         with "32b2".
  323.  
  324.  
  325.  
  326.  
  327.  
  328.                                   September 17, 1990                      5
  329.  
  330.  
  331.  
  332.  
  333.  
  334.           FORTH(3X)                                               FORTH(3X)
  335.  
  336.  
  337.                  code not ( 32b1 -- 32b2)
  338.                         "32b2" is the one's complements of "32b1".
  339.  
  340.                  constant true ( -- -1)
  341.                         The  constant "true" represented by the value minus
  342.                         one.
  343.  
  344.                  code xor ( 32b1 32b2 -- 32b3)
  345.                         "32b3" is the  bit-by-bit  exclusive-or  of  "32b1"
  346.                         with "32b2".
  347.  
  348.              Arithmetic
  349.                  The  Forth-83 Standard arithmetic word set. The tile forth
  350.                  kernel  extends  the  Forth-83  Standard  with  arithmetic
  351.                  functions  for  shifting and additional numeric constants.
  352.                  Double number width arithmetic function such as  "d+"  and
  353.                  "dnegate"  are  not  implemented as tile forth is a 32-bit
  354.                  implementation. Arithmetic errors are caught by  the  tile
  355.                  forth  kernel and passed to the application as signals. An
  356.                  exception block may be used to catch the signal.
  357.  
  358.                  code * ( w1 w2 -- w3)
  359.                         "w3"  is  the  least-significant  32  bits  of  the
  360.                         arithmetic product of "w1" times and "w2".
  361.  
  362.                  code */ ( w1 w2 w3 -- w4)
  363.                         "w1"  is  first  multiplied  by  "w2"  producing an
  364.                         intermediate 32-bit result. "w4" is  the  floor  of
  365.                         the  quotient  of  the  intermediate  32-bit result
  366.                         divided by the divisor "w3". The  product  of  "w1"
  367.                         times  "w2" is maintained as an intermediate 32-bit
  368.                         result for greater  precision  then  the  otherwise
  369.                         equivalent  sequence:  "w1  w2  *  w3  /". An error
  370.                         condition results if the divisor  is  zero  and  an
  371.                         exception is raised.
  372.  
  373.                  code */mod ( w1 w2 w3 -- w4 w5)
  374.                         "w1"  is  first  multiplied  by  "w2"  producing an
  375.                         intermediate 32-bit result. "w4" is  the  remainder
  376.                         and  "w5"  is  the  floor  of  the  quotient of the
  377.                         intermediate 32-bit result divided by  the  divisor
  378.                         "w3".  A 32-bit intermediate product is used as for
  379.                         "*/". "w4" has the same sign as "w3" or is zero. An
  380.                         error  condition results if the divisor is zero and
  381.                         an exception is raised.
  382.  
  383.                  code + ( w1 w2 -- w3)
  384.                         "w3" is the arithmetic sum of "w1" and "w2".
  385.  
  386.                  code - ( w1 w2 -- w3)
  387.                         "w3" is the result of subtracting "w2" from "w1".
  388.  
  389.                  constant -1 ( -- -1)
  390.                         Constant minus one.
  391.  
  392.  
  393.  
  394.                                   September 17, 1990                      6
  395.  
  396.  
  397.  
  398.  
  399.  
  400.           FORTH(3X)                                               FORTH(3X)
  401.  
  402.  
  403.                  constant -2 ( -- -2)
  404.                         Constant minus two.
  405.  
  406.                  constant -4 ( -- -4)
  407.                         Constant minus four.
  408.  
  409.                  code / ( w1 w2 -- w3)
  410.                         "w3" is the floor of the quotient of  "w1"  divided
  411.                         by  the divisor "w2". An error condition results if
  412.                         the divisor is zero.
  413.  
  414.                  code /mod ( w1 w2 -- w3 w4)
  415.                         "w3" is the remainder and "w4"  the  floor  of  the
  416.                         quotient  of "w1" divided by the divisor "w2". "w3"
  417.                         has the same sign as "w2"  or  is  zero.  An  error
  418.                         condition  results  if  the  divisor is zero and an
  419.                         exception is raised.
  420.  
  421.                  constant 0 ( -- 0)
  422.                         Constant zero.
  423.  
  424.                  constant 1 ( -- 1)
  425.                         Constant one.
  426.  
  427.                  code 1+ ( w1 -- w2)
  428.                         "w2" is the result of adding one to "w1"  according
  429.                         to the operation of "+".
  430.  
  431.                  code 1- ( w1 -- w2)
  432.                         "w2"  is  the  result  of  subtracting  one to "w1"
  433.                         according to the operation of "-".
  434.  
  435.                  constant 2 ( -- 2)
  436.                         Constant two.
  437.  
  438.                  code 2* ( n1 -- n2)
  439.                         "n2" is the result of arithmetically shifting  "n1"
  440.                         left one bit. The sign is included in the shift and
  441.                         remains unchanged.
  442.  
  443.                  code 2+ ( w1 -- w2)
  444.                         "w2" is the result of adding two to "w1"  according
  445.                         to the operation of "+".
  446.  
  447.                  code 2- ( w1 -- w2)
  448.                         "w2"  is  the  result  of  subtracting  two to "w1"
  449.                         according to the operation of "-".
  450.  
  451.                  code 2/ ( n1 -- n2)
  452.                         "n2" is the result of arithmetically shifting  "n1"
  453.                         right  one  bit.  The sign is included in the shift
  454.                         and remains unchanged.
  455.  
  456.  
  457.  
  458.  
  459.  
  460.                                   September 17, 1990                      7
  461.  
  462.  
  463.  
  464.  
  465.  
  466.           FORTH(3X)                                               FORTH(3X)
  467.  
  468.  
  469.                  constant 4 ( -- 4)
  470.                         Constant four.
  471.  
  472.                  code << ( n1 n2 -- n3)
  473.                         "n3" is the result of logically shifting "n1"  left
  474.                         "n2" steps.
  475.  
  476.                  code >> ( n1 n2 -- n3)
  477.                         "n3" is the result of logically shifting "n1" right
  478.                         "n2" steps.
  479.  
  480.                  code abs ( n -- u)
  481.                         "u" is the absolute value of "n".
  482.  
  483.                  code max ( n1 n2 -- n3)
  484.                         "n3" is the greater of "n1" and "n2"  according  to
  485.                         the operation of ">".
  486.  
  487.                  code min ( n1 n2 -- n3)
  488.                         "n3"  is  the  lesser of "n1" and "n2" according to
  489.                         the operation of "<".
  490.  
  491.                  code mod ( n1 n2 -- n3)
  492.                         "n3"  is  the  remainder  after  dividing  "n1"  by
  493.                         divisor "n2".  "n3" has the same sign as "n2" or is
  494.                         zero. An error condition results if the divisor  is
  495.                         zero  or  if  the  quotient  falls  outside  of the
  496.                         numerical range.
  497.  
  498.                  code negate ( n1 -- n2)
  499.                         "n2" is the two's complement  of  "n1",  i.e.,  the
  500.                         difference of zero less "n1".
  501.  
  502.                  constant nil ( -- 0)
  503.                         Constant for a nil pointer.
  504.  
  505.                  code um* ( u1 u2 -- u3)
  506.                         "u3"  is  the  unsigned product of "u1" times "u2".
  507.                         All values and arithmetic are unsigned.
  508.  
  509.                  code um/mod ( u1 u2 -- u3 u4)
  510.                         "u3" is the remainder and "u4" is the floor of  the
  511.                         quotient  after  dividing "u1" by the divisor "u2".
  512.                         All values and arithmetic are  unsigned.  An  error
  513.                         condition  results if the divisor is zero or if the
  514.                         quotient lies outside the numerical range.
  515.  
  516.              Comparison
  517.                  The Forth-83 Standard comparison word set. The tile  forth
  518.                  kernel  extends  the  standard  with an integer range test
  519.                  function.  The kernel does  not  implement  double  number
  520.                  comparison  functions.   Boolean values "true" and "false"
  521.                  are represented with "-1" and "0".
  522.  
  523.  
  524.  
  525.  
  526.                                   September 17, 1990                      8
  527.  
  528.  
  529.  
  530.  
  531.  
  532.           FORTH(3X)                                               FORTH(3X)
  533.  
  534.  
  535.                  code 0< ( n -- bool)
  536.                         Returns "true" if "n" is less than zero (negative).
  537.  
  538.                  code 0= ( w -- bool)
  539.                         Returns "true" if "w" is zero.
  540.  
  541.                  code 0> ( n -- bool)
  542.                         Returns "true" if "n" is greater than zero.
  543.  
  544.                  code < ( n1 n2 -- bool)
  545.                         Returns "true" if "n1" is less than "n2".
  546.  
  547.                  code = ( w1 w2 -- bool)
  548.                         Returns "true" if "w1" is equal to "w2"
  549.  
  550.                  code > ( n1 n2 -- bool)
  551.                         Returns "true" if "n1" is greater than "n2"
  552.  
  553.                  code ?within ( value lower upper -- bool)
  554.                         Tests  if the parameter "value" is within the range
  555.                         "lower" to "upper". Returns "true"  if  within  the
  556.                         range else "false".
  557.  
  558.                  code u< ( u1 u2 -- bool)
  559.                         Returns "true" if "u1" is less than "u2".
  560.  
  561.              Numeric Conversion
  562.                  The  Forth-83  Standard  numeric conversion functions. The
  563.                  tile forth kernel extends  the  standard  with  string  to
  564.                  number  converter, and general number literal recognition.
  565.  
  566.                  code # ( +d1 -- +d2 )
  567.                         The remainder of "+d1"  divided  by  the  value  of
  568.                         "base"  is  converted  to  a  ASCII  character  and
  569.                         appended to the output string toward  lower  memory
  570.                         addresses.  "+d2" if the quotient and is maintained
  571.                         for further processing. Typically used between "<#"
  572.                         and "#>".
  573.  
  574.                  code #> ( x -- addr +n)
  575.                         Pictured   numeric   output   conversion  is  ended
  576.                         dropping  "x".   "addr"  is  the  address  of   the
  577.                         resulting  output  string.   "+n"  is the number of
  578.                         characters in the output string.  "addr"  and  "+n"
  579.                         together are suitable for "type".
  580.  
  581.                  code #s ( +x -- 0)
  582.                         "+x"   is   converted   appending   each  resultant
  583.                         character into the pictured numeric  output  string
  584.                         until  the  quotient  is  zero.  A  single  zero is
  585.                         appended to the output string  if  the  number  was
  586.                         initially  zero.  Typically  used  between "<#" and
  587.                         "#>".
  588.  
  589.  
  590.  
  591.  
  592.                                   September 17, 1990                      9
  593.  
  594.  
  595.  
  596.  
  597.  
  598.           FORTH(3X)                                               FORTH(3X)
  599.  
  600.  
  601.                  code <# ( x -- )
  602.                         Initialize pictured numeric output conversion.  The
  603.                         words:  "<#  #  #s  hold  sign  #>"  can be used to
  604.                         specify the conversion of a number  into  an  ASCII
  605.                         text string stored in right-to-left order.
  606.  
  607.                  code ?number ( str -- [n true] or [str false]) recognizer
  608.                         Convert a string of character to a number using the
  609.                         current "base".  If the conversion is not  possible
  610.                         the   string   is  returned  with  a  "false"  flag
  611.                         indicating that the conversion failed otherwise the
  612.                         conversion  value, the number, and a "true" flag is
  613.                         returned.
  614.  
  615.                  variable base ( -- addr)
  616.                         The address of a variable  containing  the  current
  617.                         numeric conversion radix.
  618.  
  619.                  code binary ( -- )
  620.                         Set  the  input-output numeric conversion "base" to
  621.                         2.
  622.  
  623.                  code convert ( +d1 addr1 -- +d2 addr2)
  624.                         "+d2" is the result of  converting  the  characters
  625.                         within the text beginning at "addr1"+1 into digits,
  626.                         using the value of "base",  and  accumulating  each
  627.                         into  "+d1" after multiplying "+d1" by the value of
  628.                         "base". Conversion continues until an inconvertible
  629.                         character  is  encountered. "addr2" is the location
  630.                         of the first inconvertible character.
  631.  
  632.                  code decimal ( -- )
  633.                         Set the input-output numeric conversion  "base"  to
  634.                         10.
  635.  
  636.                  code hex ( -- )
  637.                         Set  the  input-output numeric conversion "base" to
  638.                         16.
  639.  
  640.                  code hold ( char -- )
  641.                         "char" is inserted into a pictured  numeric  output
  642.                         string.  Typically used between "<#" and "#>".
  643.  
  644.                  code octal ( -- )
  645.                         Set  the  input-output numeric conversion "base" to
  646.                         8.
  647.  
  648.                  code sign ( n -- )
  649.                         If "n" is negative, an ASCII "-"  (minus  sign)  is
  650.                         appended  to  the pictured numerical output string.
  651.                         Typically used between "<#" and "#>".
  652.  
  653.              Control Structures
  654.                  The Forth-83 Standard control  flow  word  set.  The  tile
  655.  
  656.  
  657.  
  658.                                   September 17, 1990                     10
  659.  
  660.  
  661.  
  662.  
  663.  
  664.           FORTH(3X)                                               FORTH(3X)
  665.  
  666.  
  667.                  forth  kernel  extends the basic set of control structures
  668.                  with    environment    arguments    access,    conditional
  669.                  compilation,  case  structure, additional loop constructs,
  670.                  and recursion words.
  671.  
  672.                  code #else ( -- ) immediate
  673.                         Used in the following form:
  674.                         <flag> #if <true-part> #else <else-part> #then
  675.                         Marks  the  beginning  of  a   "else"-part   of   a
  676.                         conditional code section.
  677.  
  678.                  code #if ( flag -- ) immediate
  679.                         Used in the following form:
  680.                         <flag> #if <true-part> [ #else <false-part> ] #then
  681.                         Marks the beginning of a conditional code  section.
  682.                         The else section is optional.
  683.  
  684.                  code #ifdef ( -- ) immediate
  685.                         Used  in the following form for testing if a symbol
  686.                         already is available:
  687.                         #ifdef <name> <true-part> [  #else  <false-part>  ]
  688.                         #then
  689.                         If  <name> is available in the current search chain
  690.                         "context" the true section of code is  executed  or
  691.                         compiled  according to mode else the optional false
  692.                         section.
  693.  
  694.                  code #ifundef ( -- ) immediate
  695.                         Used in the following form:
  696.                         #ifundef <name> <true-part> [ #else <false-part>  ]
  697.                         #then
  698.                         Performs the same function as "#ifdef" but the true
  699.                         section is executed if the symbol is not  available
  700.                         in the current search chain.
  701.  
  702.                  code #then ( -- ) immediate
  703.                         Used in the following form:
  704.                         <flag> #if <true-part> [ #else <false-part> ] #then
  705.                         Marks the end of a conditional code section.
  706.  
  707.                  code +loop ( n -- ) immediate compilation
  708.                         "n" is added to the loop index. If  the  new  index
  709.                         was incremented across the boundary between limit-1
  710.                         and limit then the loop is terminated and the  loop
  711.                         control  parameters are discarded. When the loop is
  712.                         not terminated, execution continues to  just  after
  713.                         the  corresponding  "do".  "+loop" is not available
  714.                         outside a colon definition.
  715.  
  716.                  code ?do ( w1 w2 -- ) immediate compilation
  717.                         Used in the following forms:
  718.                         ?do ...  { i | leave } ...  loop
  719.                         or
  720.                         ?do ...  { i | leave } ...  +loop
  721.  
  722.  
  723.  
  724.                                   September 17, 1990                     11
  725.  
  726.  
  727.  
  728.  
  729.  
  730.           FORTH(3X)                                               FORTH(3X)
  731.  
  732.  
  733.                         Begins a checked entry loop which terminates  based
  734.                         on  control  parameters.  The  loop index begins at
  735.                         "w2", and terminates based on the limit  "w1".  See
  736.                         "loop"  and  "+loop" for details on how the loop is
  737.                         terminated. If "w1" and "w2"  are  equal  the  loop
  738.                         section is skipped.
  739.  
  740.                  code abort ( -- )
  741.                         Clears  the data stack and performs the function of
  742.                         "quit".  No message is displayed.
  743.  
  744.                  code abort" ( flag -- ) immediate compilation
  745.                         Used in the following form:
  746.                         <flag> abort" <abort-message> "
  747.                         When later executed, if "flag" is true the  <abort-
  748.                         message> delimited by close quote, is displayed and
  749.                         then  a  system  dependent  error  abort  sequence,
  750.                         including  the  function  "abort", is performed. If
  751.                         "flag" is false, the flag is dropped and  execution
  752.                         continues.  The  blank following abort" is not part
  753.                         of the <abort-message>.
  754.  
  755.                  code again ( -- ) immediate compilation
  756.                         Used in the following form to  compile  an  eternal
  757.                         loop:
  758.                         begin ...  again
  759.                         The  loop  construct may only be left by an "abort"
  760.                         or an "exit" word in the code section of the  loop.
  761.  
  762.                  code argc ( -- num)
  763.                         Returns  the  number  of  arguments passed from the
  764.                         environment.  The first argument is always the name
  765.                         of  the  application:  "forth"  or  the name of the
  766.                         start symbol.
  767.  
  768.                  code argv ( n -- str)
  769.                         Given an index returns the  corresponding  argument
  770.                         string.  The  "string" vocabulary words may be used
  771.                         for process an argument string.
  772.  
  773.                  code begin ( -- ) immediate compilation
  774.                         Used in the following forms:
  775.                         begin ...  <flag> while ...  repeat
  776.                         or
  777.                         begin ...  <flag> until
  778.               grotty:t:temp:11317:fatal error: integer expected
  779.           or
  780.                         begin ...  again
  781.                         "begin" marks the start  of  a  word  sequence  for
  782.                         repetitive  execution.  A "begin-while-repeat" loop
  783.                         will repeat until <flag>  is  false.  "begin-until"
  784.                         loop  will  be  repeated  until  <flag> is true and
  785.                         "begin-again" will  repeat  until  "abort"-ed.  The
  786.                         words  after  "until" and "repeat" will be executed
  787.                         when either loop is finished.
  788.  
  789.  
  790.  
  791.                                   September 17, 1990                     12
  792.  
  793.  
  794.  
  795.  
  796.  
  797.           FORTH(3X)                                               FORTH(3X)
  798.  
  799.  
  800.                  code bye ( -- )
  801.                         Leaves the interaction level and exits to the outer
  802.                         support system (if any).
  803.  
  804.                  code case ( value -- ) immediate compilation
  805.                         Used in the following form:
  806.                         case <case-structure>  { <default-part> } endcase
  807.                         to  mark  the  beginning  of a case structure which
  808.                         should contain a one or several case statements:
  809.                         <case-value> of <case-part> endof
  810.                         The code section after the  last  case  value  part
  811.                         will  receive "value" as a parameter thus a default
  812.                         behavior is easy implemented. The  default  section
  813.                         may  only  copy  this  value  as  "endcase"  is  an
  814.                         implicit "drop".
  815.  
  816.                  code do ( w1 w2 -- )     immediate compilation
  817.                         Used in the following forms:
  818.                         do ...  { i | leave } ...  loop
  819.                         or
  820.                         do ...  { i | leave } ...  +loop
  821.                         Begins a loop which  terminates  based  on  control
  822.                         parameters.   The  loop  index  begins at "w2", and
  823.                         terminates based on the limit "w1". See "loop"  and
  824.                         "+loop"  for details on how the loop is terminated.
  825.                         The loop is always executed at least once.
  826.  
  827.                  code else ( -- ) immediate compilation
  828.                         Used in the following form:
  829.                         <flag> if <true-part> else <false-part> then
  830.                         in a conditional structure to mark the beginning of
  831.                         the  false  section.  This section is executed when
  832.                         the <flag> is "false". The  true  section  is  then
  833.                         skipped.
  834.  
  835.                  code endcase ( -- ) immediate compilation
  836.                         Used in the following form:
  837.                         case <case-structure>  { <default-part> } endcase
  838.                         to mark the end of a case structure.
  839.  
  840.                  code endof ( -- ) immediate compilation
  841.                         Used in the following form:
  842.                         <case-value> of <case-part> endof
  843.                         to mark the end of a cast value structure.
  844.  
  845.                  code execute ( addr -- )
  846.                         The   word   definition   indicated  by  "addr"  is
  847.                         executed. An error condition exists  if  "addr"  is
  848.                         not a compilation address.
  849.  
  850.                  code exit ( -- ) compilation
  851.                         Compiled  within  a colon definition such that when
  852.                         executed, the colon definition returns  control  to
  853.                         the   definition  that  passed  control  to  it  by
  854.  
  855.  
  856.  
  857.                                   September 17, 1990                     13
  858.  
  859.  
  860.  
  861.  
  862.  
  863.           FORTH(3X)                                               FORTH(3X)
  864.  
  865.  
  866.                         returning control to the return point on the top of
  867.                         the  return stack. An error condition exists if the
  868.                         top of the return stack does not  contain  a  valid
  869.                         return point. May not be used within a "do-loop" or
  870.                         "do-+loop" or an "exception"-block.
  871.  
  872.                  code i ( -- w) compilation
  873.                         "w" is a copy of the current loop index.  May  only
  874.                         be used in the form:
  875.                         do ...  { i | leave } ...  loop
  876.                         or
  877.                         do ...  { i | leave } ...  +loop
  878.                         "i"  is  not  visible  outside  a colon definition,
  879.                         i.e., when text interpreting  and  should  only  be
  880.                         used within a loop-block.
  881.  
  882.                  code if ( flag -- ) immediate compilation
  883.                         Used in the following form:
  884.                         <flag> if <true-part> [ else <else-part> ] then
  885.                         If  "flag"  is  true,  the words following "if" are
  886.                         executed and the words following "else" until  just
  887.                         after  "then"  are  skipped.  The  "else"  part  is
  888.                         optional. If  "flag"  is  false,  words  from  "if"
  889.                         through  "else",  or from "if" through "then" (when
  890.                         no "else" is used) are skipped.
  891.  
  892.                  code j ( -- w) compilation
  893.                         "w" is a copy of the index of the next outer  loop.
  894.                         May  only  be  used  within  a  nested "do-loop" or
  895.                         "do-+loop" in the form:
  896.                         do ...  do ...  { i | j | leave  }  ...   loop  ...
  897.                         loop
  898.                         "j"  is  not  visible  outside  a colon definition,
  899.                         i.e., when text interpreting.
  900.  
  901.                  code leave ( -- ) compilation
  902.                         Transfers execution to just beyond the next  "loop"
  903.                         or  "+loop".   The  loop is terminated and the loop
  904.                         control parameters are discarded. May only be  used
  905.                         in the following forms:
  906.                         do ...  { i | leave } ...  loop
  907.                         or
  908.                         do ...  { i | leave } ...  +loop
  909.                         "leave"  may appear within other control structures
  910.                         which are nested within  the  "do-loop"  structure.
  911.                         More  than one "leave" may appear within a do-loop.
  912.  
  913.                  code loop ( -- ) immediate compilation
  914.                         Increments the "do-loop" index by one. If  the  new
  915.                         index  was  incremented across the boundary between
  916.                         limit-1 and limit the loop is  terminated  and  the
  917.                         loop  control  parameters  are  discarded. When the
  918.                         loop is not terminated, execution continues to just
  919.                         after the corresponding "do".
  920.  
  921.  
  922.  
  923.                                   September 17, 1990                     14
  924.  
  925.  
  926.  
  927.  
  928.  
  929.           FORTH(3X)                                               FORTH(3X)
  930.  
  931.  
  932.                  code of ( value -- ) immediate compilation
  933.                         Used in the following form:
  934.                         <case-value> of <case-part> endof
  935.                         within a case structure to define a value case.
  936.  
  937.                  code quit ( -- )
  938.                         Clears  the  return  stack,  sets  interpret state,
  939.                         accepts new input from the  current  input  device,
  940.                         and  begins  text  interpretation.  No  messages is
  941.                         displayed.
  942.  
  943.                  code recurse ( -- ) immediate compilation
  944.                         Used within a definition to make a  recursive  call
  945.                         to the current definition.
  946.  
  947.                  code repeat ( -- ) immediate compilation
  948.                         Used in the following form:
  949.                         begin ...  <flag> while ...  repeat
  950.                         At  execution-time, "repeat" continues execution to
  951.                         just after the corresponding "begin".
  952.  
  953.                  code tail-recurse ( -- ) immediate compilation
  954.                         Used within a definition to create a recursive call
  955.                         to  the  current  definition  without saving return
  956.                         status. This is  an  efficient  way  of  generating
  957.                         iterative  forms  as  tail  recursive  calls may be
  958.                         performed any number of times within  a  definition
  959.                         and corresponds to a branch to the beginning of the
  960.                         definition.
  961.  
  962.                  code then ( -- ) immediate compilation
  963.                         Used in the following form:
  964.                         <flag> if <true-part> [ else <else-part> ] then
  965.                         Marks the end of a conditional statement  "if-else-
  966.                         then".
  967.  
  968.                  code until ( flag -- ) immediate compilation
  969.                         Used in the following form:
  970.                         begin ...  <flag> until
  971.                         Marks  the  end  of a "begin-until" loop which will
  972.                         terminate based on "flag". If "flag" is  true,  the
  973.                         loop  is terminated.  If "flag" is false, execution
  974.                         continues to just after the corresponding  "begin".
  975.  
  976.                  code while ( flag -- ) immediate compilation
  977.                         Used in the following form:
  978.                         begin ...  <flag> while ...  repeat
  979.                         Selects conditional execution based on "flag". When
  980.                         "flag" is true, execution continues to  just  after
  981.                         the  "while"  through  to  the  "repeat" which then
  982.                         continues execution to just after the "begin". When
  983.                         "flag"  is false, execution continues to just after
  984.                         the "repeat", exiting the control structure.
  985.  
  986.  
  987.  
  988.  
  989.                                   September 17, 1990                     15
  990.  
  991.  
  992.  
  993.  
  994.  
  995.           FORTH(3X)                                               FORTH(3X)
  996.  
  997.  
  998.              Terminal Input/Output
  999.                  The Forth-83 Standard terminal interaction functions.  The
  1000.                  tile  forth  kernel  extends  the  basic  set of input and
  1001.                  output functions with field format output  and  access  of
  1002.                  the  current  input  source file name and the current line
  1003.                  number count.
  1004.  
  1005.                  code . ( n -- )
  1006.                         The absolute value of "n" is displayed  in  a  free
  1007.                         field  format  with  a leading minus sign if "n" is
  1008.                         negative. A space is emit after the number.
  1009.  
  1010.                  code ." ( -- ) immediate compilation
  1011.                         Used  in  the  following   form   within   a   code
  1012.                         definition:
  1013.                         <output-string> "
  1014.                         Later   execution   will   display  the  characters
  1015.                         <output-string>  up  to  but  but   including   the
  1016.                         delimiter  (close-quote).  The  blank following the
  1017.                         "." " is not part of the  <output-string>  but  the
  1018.                         word separator.
  1019.  
  1020.                  code .( ( -- ) immediate
  1021.                         Used in the following form:
  1022.                         .( <output-comment> )
  1023.                         The  characters  <output-comment>  up  to  but  not
  1024.                         including the delimiter  (closing-parenthesis)  are
  1025.                         displayed.  The blank following ".(" is not part of
  1026.                         the <output-comment>.
  1027.  
  1028.                  code .s ( -- )
  1029.                         Displays the current parameter  stack  contents  in
  1030.                         the format:
  1031.                         [ <depth> ] <bottom> \ ... \ <top>
  1032.  
  1033.                  code ascii ( -- char) immediate
  1034.                         Used in the following form:
  1035.                         ascii <character> ( -- char)
  1036.                         to create a character literal.
  1037.  
  1038.                  code cr ( -- )
  1039.                         Emits  ASCII  characters  carriage-return and line-
  1040.                         feed.
  1041.  
  1042.                  code emit ( x -- )
  1043.                         The  least-significant  7-bit  ASCII  character  is
  1044.                         displayed.
  1045.  
  1046.                  code expect ( addr +n -- )
  1047.                         Receive  characters and store each into memory.
  1048.  
  1049.  
  1050.  
  1051.  
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057.  
  1058.